<template>
  <div class="register-page">
    <van-nav-bar title="账号注册" left-arrow @click-left="$router.go(-1)"/>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入用户名"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
      />
      <div style="margin: 25px">
        <van-button square block color="#21b97a" native-type="submit">注册</van-button>
      </div>
      <router-link to="/login" class="link">有账户，请登录~</router-link>
    </van-form>
  </div>
</template>

<script>
import { register } from '@/api/uesr'
export default {
  name: 'register-page',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      await register(values)
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 12px;
  padding-left: 30px;
  float: left;
}
</style>
